<?php
/**
 * Created by PhpStorm.
 * User: ewen
 * Date: 4/27/21
 * Time: 2:02 PM
 */

namespace app\common\model;


class WebInviter extends Common
{

    /**
     * 获取用户邀请的人
     * @param $userID
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getSonsByUserID($userID)
    {
        $where = [
            'inviter_id' => $userID
        ];
        $list = self::field('inviter_id,invitee_id')->where($where)->select();
        return $list;
    }

    /**
     * 获取邀请的人实名数量
     * @param $userID
     * @return int|string
     */
    public static function getSonsCertificationNum($userID)
    {
        $sons = self::getSonsByUserID($userID);
        $count = 0;
        if (count($sons)) {
            $count = WebCertification::where([
                'user_id' => ['in', array_column($sons, 'invitee_id')],
                'review_status' => 1
            ])->count();
        }
        return $count;
    }
}